package com.puzzlebazar.client.heyawake;

import com.puzzlebazar.client.squaregrid.view.HighlightConstraints;
import com.puzzlebazar.client.util.Observable;
import com.puzzlebazar.client.util.ObservableImpl;
import com.puzzlebazar.client.util.Observer;
import com.puzzlebazar.client.util.Recti;
import com.puzzlebazar.client.util.Vec2i;

public class HighlightRoomConstraints extends ObservableImpl 
	implements HighlightConstraints, Observer {

	private final HeyawakeModel model;
	
	public HighlightRoomConstraints( HeyawakeModel model ) {
		this.model = model;
		model.addObserver( this );
	}
	
	@Override
	public boolean canHandleCell(Vec2i cellLoc) {
		// TODO check that the location is valid
		return true;
	}

	@Override
	public boolean canHandleHorizontalEdge(Vec2i edgeLoc) {
		return false;
	}

	@Override
	public boolean canHandleVertex(Vec2i vertexLoc) {
		return false;
	}

	@Override
	public boolean canHandleVerticalEdge(Vec2i edgeLoc) {
		return false;
	}

	@Override
	public Recti cellGroup(Vec2i cellLoc) {		
		Recti result = null;
		try {
			Room room = model.findRoomAt( cellLoc );
			if( room != null ) result = room.getRoomArea();
		} catch (Exception exception) {
			exception.printStackTrace();
		}
		
		return result;
	}

	@Override
	public void update(Observable observable, Object arg) {
		setChanged();
		notifyObservers();
	}
	
	@Override
	public void release() {
		super.release();
		model.deleteObserver( this );
	}

}
